package com.katze.common.controller;

import com.katze.common.http.WebClientService;
import jakarta.annotation.Resource;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public abstract class WebClientController<T> extends BaseController{

    private final Class<T> cs;

    @Resource
    private WebClientService webClientService;

    public WebClientController() {
        Type type = getClass().getGenericSuperclass();
        type = ((ParameterizedType) type).getActualTypeArguments()[0];
        if (type instanceof Class<?>) {
            @SuppressWarnings("unchecked")
            Class<T> clazz = (Class<T>) type;
            this.cs = clazz;
        } else {
            this.cs = null;
        }
    }

    public T execute(String uid) {
        return webClientService.getHttpServiceProxyFactory(uid, cs);
    }
}
